package com.peanut.server.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.domain.bo.TabCarSeriesBO;
import com.peanut.dto.TabCarAgeDTO;
import com.peanut.mapper.TabCarAgeMapper;
import com.peanut.server.TabCarAgeServer;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@Service
public class TabCarAgeimpl implements TabCarAgeServer {
    @Resource
    private TabCarAgeMapper tabCarAgeMapper;

    @Override
    public List<TabCarAgeDTO> TabCarAge() {
        List<TabCarSeriesBO> tabCarSeries = tabCarAgeMapper.selectAlls();
        String s = JSONObject.toJSONString(tabCarSeries);
        List<TabCarAgeDTO> tabCarAgeList = JSONObject.parseArray(s, TabCarAgeDTO.class);
        return tabCarAgeList;
    }

    @Override
    public void addDicCarType(TabCarAgeDTO dicCarTypeBOS) {
        TabCarSeriesBO dicCarType = new TabCarSeriesBO();
        dicCarType.setCarSeriesId(dicCarTypeBOS.getSeriesId());
        dicCarType.setCarSeriesName(dicCarTypeBOS.getCarAgeName());
        tabCarAgeMapper.insert(dicCarType);

    }

    @Override
    public List<TabCarAgeDTO> findDicTypeCarByName(String carTypeName) {
        QueryWrapper<TabCarSeriesBO> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("car_series_name",carTypeName);
        List<TabCarSeriesBO> list=tabCarAgeMapper.selectAlls();
        String s = JSONObject.toJSONString(list);
        List<TabCarAgeDTO> carTypeBOS=JSONObject.parseArray(s,TabCarAgeDTO.class);
        return carTypeBOS;
    }

    @Override
    public void deleteBathByIdsCarType(List<Integer> list) {
        tabCarAgeMapper.deleteBatchIds(list);
    }
    @Override
    public List<TabCarSeriesBO> recommend(BigDecimal longitude, BigDecimal latitude) {
        List<TabCarSeriesBO> shopList = tabCarAgeMapper.recommend(longitude, latitude);
        return shopList;
    }


}
